﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DatabasePlugin
{
    public partial class frmConfig : Form
    {
        public string DatabaseType;
        public string ConnectionString;
        public bool Enable;

        public frmConfig(NameValueCollection current)
        {
            InitializeComponent();
            try
            {
                switch (current["databaseplugin_databasetype"].ToLower())
                {
                    case "access":
                        ddType.SelectedIndex = 0;
                        break;

                    case "mssql":
                        ddType.SelectedIndex = 1;
                        break;

                    default:
                        ddType.SelectedIndex = 2;
                        break;
                }
                txtConn.Text = current["databaseplugin_connectionstring"];
                chkEnabled.Checked = bool.Parse(current["databaseplugin_enabled"]);
            }
            catch
            {
                // just ignore
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Enable = chkEnabled.Checked;
            ConnectionString = txtConn.Text;
            switch (ddType.SelectedIndex)
            {
                case 0:
                    DatabaseType = "access";
                    break;

                case 1:
                    DatabaseType = "mssql";
                    break;

                default:
                    DatabaseType = "mysql";
                    break;
            }

        }

    }
}
